<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD><TITLE>Tk_Main manual page - Tk Library Procedures</TITLE>
<link rel="stylesheet" href="../docs.css" type="text/css" media="all">
</HEAD>
<BODY><H2><a href="../contents.htm">Tcl8.6.11/Tk8.6.11 Documentation</a> <small>&gt;</small> <a href="contents.htm">Tk C API</a> <small>&gt;</small> Tk_Main</H2>
<H3><A HREF="../UserCmd/contents.htm">Tcl/Tk Applications</A> | <A HREF="../TclCmd/contents.htm">Tcl Commands</A> | <A HREF="../TkCmd/contents.htm">Tk Commands</A> | <A HREF="../ItclCmd/contents.htm">[incr Tcl] Package Commands</A> | <A HREF="../SqliteCmd/contents.htm">SQLite3 Package Commands</A> | <A HREF="../TdbcCmd/contents.htm">TDBC Package Commands</A> | <A HREF="../TdbcmysqlCmd/contents.htm">tdbc::mysql Package Commands</A> | <A HREF="../TdbcodbcCmd/contents.htm">tdbc::odbc Package Commands</A> | <A HREF="../TdbcpostgresCmd/contents.htm">tdbc::postgres Package Commands</A> | <A HREF="../TdbcsqliteCmd/contents.htm">tdbc::sqlite3 Package Commands</A> | <A HREF="../ThreadCmd/contents.htm">Thread Package Commands</A> | <A HREF="../TclLib/contents.htm">Tcl C API</A> | <A HREF="../TkLib/contents.htm">Tk C API</A> | <A HREF="../ItclLib/contents.htm">[incr Tcl] Package C API</A> | <A HREF="../TdbcLib/contents.htm">TDBC Package C API</A></H3>
<H3><A NAME="M2">NAME</A></H3>
Tk_Main &mdash; main program for Tk-based applications
<H3><A NAME="M3">SYNOPSIS</A></H3>
<B>#include &lt;tk.h&gt;</B><BR>
<B>Tk_Main</B>(<I>argc, argv, appInitProc</I>)<BR>
<H3><A NAME="M4">ARGUMENTS</A></H3>
<DL class="arguments">
<DT>int <B><A HREF="../TclCmd/tclvars.htm">argc</A></B> (in)<DD>
Number of elements in <I>argv</I>.
<P><DT>char <B>*argv[]</B> (in)<DD>
Array of strings containing command-line arguments. On Windows, when
using -DUNICODE, the parameter type changes to wchar_t *.
<P><DT>Tcl_AppInitProc <B>*appInitProc</B> (in)<DD>
Address of an application-specific initialization procedure.
The value for this argument is usually <B><A HREF="../TclLib/AppInit.htm">Tcl_AppInit</A></B>.
<P></DL>
<H3><A NAME="M5">DESCRIPTION</A></H3>
<B>Tk_Main</B> acts as the main program for most Tk-based applications.
Starting with Tk 4.0 it is not called <B>main</B> anymore because it
is part of the Tk library and having a function <B>main</B>
in a library (particularly a shared library) causes problems on many
systems.
Having <B>main</B> in the Tk library would also make it hard to use
Tk in C++ programs, since C++ programs must have special C++
<B>main</B> functions.
<P>
Normally each application contains a small <B>main</B> function that does
nothing but invoke <B>Tk_Main</B>.
<B>Tk_Main</B> then does all the work of creating and running a
<B><A HREF="../UserCmd/wish.htm">wish</A></B>-like application.
<P>
When it is has finished its own initialization, but before
it processes commands, <B>Tk_Main</B> calls the procedure given by
the <I>appInitProc</I> argument.  This procedure provides a
&ldquo;hook&rdquo;
for the application to perform its own initialization, such as defining
application-specific commands.  The procedure must have an interface
that matches the type <B>Tcl_AppInitProc</B>:
<PRE>typedef int <B>Tcl_AppInitProc</B>(
        <A HREF="../TclLib/Interp.htm">Tcl_Interp</A> *<I>interp</I>);</PRE>
<I>AppInitProc</I> is almost always a pointer to <B><A HREF="../TclLib/AppInit.htm">Tcl_AppInit</A></B>;
for more details on this procedure, see the documentation
for <B><A HREF="../TclLib/AppInit.htm">Tcl_AppInit</A></B>.
<P>
<B>Tk_Main</B> functions much the same as <B><A HREF="../TclLib/Tcl_Main.htm">Tcl_Main</A></B>.  In particular,
<B>Tk_Main</B> supports both an interactive mode and a startup script
mode, with the file name and encoding of a startup script under the
control of the <B><A HREF="../TclLib/Tcl_Main.htm">Tcl_SetStartupScript</A></B> and <B><A HREF="../TclLib/Tcl_Main.htm">Tcl_GetStartupScript</A></B>
routines. However it calls <B><A HREF="../TkLib/MainLoop.htm">Tk_MainLoop</A></B> after processing any
supplied script, and in interactive uses events registered with
<B><A HREF="../TclLib/CrtFileHdlr.htm">Tcl_CreateFileHandler</A></B> to process user input.
<H3><A NAME="M6">SEE ALSO</A></H3>
<B><A HREF="../TclLib/DoOneEvent.htm">Tcl_DoOneEvent</A></B>
<H3><A NAME="M7">KEYWORDS</A></H3>
<A href="../Keywords/A.htm#application-specific initialization">application-specific initialization</A>, <A href="../Keywords/C.htm#command-line arguments">command-line arguments</A>, <A href="../Keywords/M.htm#main program">main program</A>
<div class="copy">Copyright &copy; 1994 The Regents of the University of California.
<BR>Copyright &copy; 1994-1996 Sun Microsystems, Inc.
</div>
</BODY></HTML>
